package com.zuihai.app.mvp.ui.adapter;

import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.zuihai.app.R;
import com.zuihai.app.mvp.model.entity.Favour;
import com.zuihai.app.mvp.ui.holder.BaseViewHolderWraper;
import com.zuihai.app.mvp.ui.utils.AccountHelper;

import java.util.List;

/**
 * Created by Administrator on 2017/6/8 0008.
 */

public class DetailFavourAdapter extends BaseQuickAdapter<Favour.User, BaseViewHolderWraper> {

    private OnCareClickListener onCareClickListener;

    public DetailFavourAdapter(@Nullable List<Favour.User> data) {
        super(R.layout.layout_item_detail_favour, data);
    }

    public void setOnCareClickListener(OnCareClickListener onFavourClickListener) {
        this.onCareClickListener = onFavourClickListener;
    }

    @Override
    protected void convert(BaseViewHolderWraper helper, Favour.User item) {
        if (!TextUtils.isEmpty(item.avatarUri)) {
            helper.loadImage(R.id.iv_avatar, item.avatarUri);
        }
        helper.setText(R.id.tv_name, item.name);
        helper.setText(R.id.tv_desc, item.mome);
        String uid = AccountHelper.getInstance().getUid();
        helper.getView(R.id.tv_care).setVisibility(item.id.equals(uid) ? View.GONE : View.VISIBLE);
        helper.setText(R.id.tv_care, item.isCare ? "已关注" : "关注");
        helper.getView(R.id.tv_care).setSelected(item.isCare);
        helper.getView(R.id.tv_care).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onCareClickListener != null){
                    onCareClickListener.onCareClick(item);
                }
                item.isCare = !item.isCare;
                helper.setText(R.id.tv_care, item.isCare ? "已关注" : "关注");
                helper.getView(R.id.tv_care).setSelected(item.isCare);
            }
        });
        helper.getView(R.id.tv_name).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onCareClickListener != null){
                    onCareClickListener.onUserClick(item);
                }
            }
        });
        helper.getView(R.id.iv_avatar).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onCareClickListener != null){
                    onCareClickListener.onUserClick(item);
                }
            }
        });
    }

    public interface OnCareClickListener {
        void onCareClick(Favour.User user);
        void onUserClick(Favour.User user);
    }
}
